﻿Public Class PersonExplorer
    Inherits ExplorerTreeList

    Public PersonPL As PLBase

    Public Sub New(ByVal aQueryName As String)
        MyBase.New(aQueryName)
    End Sub

    Public Sub New()
        MyBase.New()
    End Sub

    Public Overrides Sub PopulateDetailSection()
        Me.Cursor = Cursors.WaitCursor
        '
        If aGridControl IsNot Nothing Then
            aGridControl.Dispose()
            aGridControl = Nothing
        End If
        '
        Dim guidParent As Guid = Nothing
        Dim guidEnfant As Guid = DirectCast(NodeDataRow(Me.KeyFieldName), Guid)
        Dim frmCaption As String = Nothing
        Dim DescriptionLang As String = "_PRM"

        If AppManager.ApplicationOption.DescriptionColumnIndex = 3 Then
            DescriptionLang = "_ALT"
        Else
            DescriptionLang = "_PRM"
        End If

        'frmCaption = NodeDatarow("Description" & DescriptionLang)

        Select Case FocusedNodeLevel
            Case 0
                If AppManager.ApplicationOption.DescriptionColumnIndex = 3 Then
                    frmCaption = "Liste des personnes"
                Else
                    frmCaption = "Person List"
                End If
                ShowAllPerson()
            Case 1
                If NodeDataRow.Table.Columns.Contains("Description_PRM") Then
                    frmCaption = String.Format("{0}", NodeDataRow("Description_PRM"))
                Else
                    frmCaption = "Description_PRM"
                End If

                ShowByPerson(guidEnfant)
            Case Else
        End Select

        '
        'On trouve la form pour effacer les controle dedans et ensuite remettre le bon.
        'Comme ca on change le Detail selon la ligne dans L'explorer
        For Each aFrm As XtraForm In Me.ParentForm.MdiChildren
            If aFrm.Name = PanelName Then
                aFrm.Controls.Clear()
                aFrm.Controls.Add(aGridControl)
                aFrm.Text = frmCaption
                aFrm.Show()
                aFrm.Focus()
            End If
            aFrm.Refresh()
        Next

        Me.Cursor = Cursors.Default
    End Sub

    Public Overridable Sub ShowAllPerson()
        PersonPL = PLBase.CreateInstanceOf(PLTypeOf.Persons_PL, "Persons")

        'Scoper nouveau PL en haut en haut        
        aGridControl = New GridExtPL() With {.Dock = DockStyle.Fill, .Pl = PersonPL, .SecureGrid = True, .Name = "Person List", .FormCtrlCD = Nothing}

        aGridControl.GridActionOptionList.Add(New ActionOption("Person", "ACT_00165", "CreateSQLUserSSPI", AddressOf Create_SQLUser_SSPI, True, True))
        aGridControl.GridActionOptionList.Add(New ActionOption("Person", "ACT_00166", "CreateSQLUserSQL", AddressOf Create_SQLUser_SQL, True, True))
        aGridControl.GridActionOptionList.Add(New ActionOption("Person", "ACT_00186", "CreatePersonToProduct", AddressOf Persons_SaveToProduct, True, True))
        aGridControl.GridActionOptionList.Add(New ActionOption("Person", "ACT_00186", "CreatePersonToProduct", AddressOf Persons_SaveToProduct, True, True))

    End Sub

    Public Overridable Sub ShowByPerson(ByVal personID As System.Guid)
        PersonPL = PLBase.CreateInstanceOf(PLTypeOf.Persons_PL, "Persons")

        'Scoper nouveau PL en haut en haut        
        aGridControl = New GridExtPL() With {.Dock = DockStyle.Fill, .Pl = PersonPL, .SecureGrid = True, .Name = "Person List", .FormCtrlCD = MyBase.PanelName}
        PersonPL.SQLWhere = String.Format("PersonID = '{0}'", personID)

        aGridControl.GridActionOptionList.Add(New ActionOption("Person", "ACT_00165", "CreateSQLUserSSPI", AddressOf Create_SQLUser_SSPI, True, True))
        aGridControl.GridActionOptionList.Add(New ActionOption("Person", "ACT_00166", "CreateSQLUserSQL", AddressOf Create_SQLUser_SQL, True, True))
        aGridControl.GridActionOptionList.Add(New ActionOption("Person", "ACT_00186", "Create Person To Product", AddressOf Persons_SaveToProduct, True, True))
        aGridControl.GridActionOptionList.Add(New ActionOption("Person", "ACT_00194", "CreatePersonToSociety", AddressOf Persons_SaveToSociety, True, True))


    End Sub

End Class
